<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
	<script type="text/javascript" src="../layui/layui.js"></script>
	<link rel="stylesheet" href="../layui/css/layui.css">
	<link rel="stylesheet" type="text/css" href="../css/backer/BuyHouse.css"/>
	<script src="../js/jquery-1.12.4.js"></script>
</head>
<body>
<div class="head-div">
	<i class="layui-icon layui-icon-dollar">&nbsp; <span onclick="location.href='http://localhost:8080/backer/syshomepage';" style="cursor: pointer;">返回</span>&nbsp;&nbsp;/&nbsp;&nbsp;信息管理&nbsp;&nbsp;/&nbsp;&nbsp;发布信息</i>
</div>
<div class="maintemplate"><br /><br />
	<form action="" method="post">
		<div class="margin-bottom">
			<div class="lable-left">
				<span class="redstar">* </span>选择类型
			</div><input hidden name="online" value="true">
			<select name="houseType.id" class="obtain1 selecthouse cursor isblue obtain housetypeid" >
				<option class="housetype" value="">下拉选择类型</option>
			</select>
			<span class="nextspan">请选择多层住宅</span>
		</div>
		<div class="margin-bottom">
			<div class="lable-left">
				<span class="redstar">* </span>选择区域
			</div>
			<select name="area.id" class="obtain3 selectarea cursor isblue obtain " >
				<option class="areas" value="">下拉选择区域</option>
			</select>
			<span class="nextspan">请选择区域</span>
		</div>
		<div class="margin-bottom">
			<div class="lable-left">
				<span class="redstar">* </span>面积
			</div>
			<input name="area.id" type="number" class="obtain7 input-area isblue area obtain" placeholder="请输入面积 m²(平方)" />
			<span class="nextspan">请输入面积</span>
		</div>
		<div class="margin-bottom">
			<div class="lable-left">
				<span class="redstar">* </span>求购预算
			</div>
			<input name="price" type="number" class="obtain8 input-price isblue price obtain" placeholder="请输入求购预算 万元" />
			<span class="nextspan">请输入求购预算</span>
		</div>
		<!--<div class="margin-bottom">
            <div class="lable-left">
                <span class="redstar">* </span>屋内设备
            </div>
            <div class="rmp">
                <input name="roomFacilities" class="roompro obtain15 obtain" value="水" type="checkbox" />&nbsp;&nbsp;<span>水</span>
                <input name="roomFacilities" class="roompro obtain15 obtain" value="电" type="checkbox" />&nbsp;&nbsp;<span>电</span>
                <input name="roomFacilities" class="roompro obtain15 obtain" value="天然气" type="checkbox" />&nbsp;&nbsp;<span>天然气</span>
                <input name="roomFacilities" class="roompro obtain15 obtain" value="煤气" type="checkbox" />&nbsp;&nbsp;<span>煤气</span>
                <input name="roomFacilities" class="roompro obtain15 obtain" value="暖气" type="checkbox" />&nbsp;&nbsp;<span>暖气</span>
                <input name="roomFacilities" class="roompro obtain15 obtain" value="互联网" type="checkbox" />&nbsp;&nbsp;<span>互联网</span>
                <input name="roomFacilities" class="roompro obtain15 obtain" value="有线电视" type="checkbox" />&nbsp;&nbsp;<span>有线电视</span>
                <input name="roomFacilities" class="roompro obtain15 obtain" value="电话" type="checkbox" />&nbsp;&nbsp;<span>电话</span>
            </div>
            <span class="nextspan">至少选择一项</span>
        </div><br />-->
		<div class="margin-bottom" style="clear: both;margin-top: 20px;"><br />
			<div class="lable-left">
				<span class="redstar">* </span>信息标题
			</div>
			<input type="text" name="title" class="obtain12 selecttitle isblue lc obtain" placeholder="请输入标题">
			<span class="nextspan">请输入标题</span>
		</div>
		<div class="margin-bottom" style="clear: both;margin-top: 20px;"><br />
			<div class="lable-left">
				<span class="redstar">* </span>描述
			</div>
			<textarea name="describe" class="txtarea obtain13 obtain"></textarea>
			<span class="nextspan">请输入描述</span>
		</div>
		<div class="margin-bottom" style="clear: both;margin-top: 20px;"><br />
			<div class="lable-left">
				<span class="redstar">* </span>联系人
			</div>
			<input readonly="readonly" th:value="${session.user.linkman}" type="text" class="selecttitle isblue obtain16 obtain" value="张三"/>
			<span class="nextspan">请输入联系人</span>
		</div>
		<div class="margin-bottom" style="clear: both;margin-top: 20px;"><br />
			<div class="lable-left">
				<span class="redstar">* </span>选择有效时间
			</div>
			<div class="choosedate">
				<div class="choosedate-div">
					<input type="radio" checked="checked" name="etime" value="7" />&nbsp;7天
				</div>
				<div class="choosedate-div">
					<input type="radio" name="etime" value="30" />&nbsp;30天
				</div>
				<div class="choosedate-div">
					<input type="radio" name="etime" value="60" />&nbsp;60天
				</div>
			</div>
			<span class="nextspan obtain obtain20">请选择有效时间</span>
		</div>
		<span name="name"></span>
		<div class="margin-bottom" style="clear: both;margin-top: 20px;"><br />
			<input class="upgrade" type="button" style="margin-left: 174px;" value="提交发布" />
		</div>
		<input hidden value="1" name="user.uid">
		<input hidden name="type" value="2">
		<input hidden name="online" value="1">
		<input hidden name="status" value="已上架">

	</form>
</div>
</body>
<script>
	$(".upgrade").click(function(){

		if ($("[name=linkman]").val()==""){
			$("[name=linkman]").siblings("span").css("visibility","visible");
		}else{
			$("[name=linkman]").siblings("span").css("visibility","hidden");
		}

		if ($(".facilitieid").val()==""){
			$(".facilitieid").siblings("span").css("visibility","visible");
		}else{
			$(".facilitieid").siblings("span").css("visibility","hidden");
		}

		if ($("[name=describe]").val()==""){
			$("[name=describe]").siblings("span").css("visibility","visible");
		}else{
			$("[name=describe]").siblings("span").css("visibility","hidden");
		}

		if ($("[name=title]").val()==""){
			$("[name=title]").siblings("span").css("visibility","visible");
		}else{
			$("[name=title]").siblings("span").css("visibility","hidden");
		}

		if ($("[name=storeyUser]").val()==""){
			$("[name=storeyUser]").siblings("span").css("visibility","visible");
		}else{
			$("[name=storeyUser]").siblings("span").css("visibility","hidden");
		}

		if ($("[name=storeySum]").val()==""){
			$("[name=storeySum]").siblings("span").siblings("span").css("visibility","visible");
		}else{
			$("[name=storeySum]").siblings("span").css("visibility","hidden");
		}

		if ($(".renovation").siblings("span").val()==""){
			$(".renovation").siblings("span").css("visibility","visible");
		}else{
			$(".renovation").siblings("span").css("visibility","hidden");
		}

		if ($("[name=price]").val()==""){
			$("[name=price]").siblings("span").css("visibility","visible");
		}else{
			$("[name=price]").siblings("span").css("visibility","hidden");
		}

		if ($("[name=houseSize]").val()==""){
			$("[name=houseSize]").siblings("span").css("visibility","visible");
		}else{
			$("[name=houseSize]").siblings("span").css("visibility","hidden");
		}

		if ($("[name=defend]").val()==""){
			$("[name=defend]").siblings("span").css("visibility","visible");
		}else{
			$("[name=defend]").siblings("span").css("visibility","hidden");
		}

		if ($("[name=hall]").val()==""){
			$("[name=hall]").siblings("span").css("visibility","visible");
		}else{
			$("[name=hall]").siblings("span").css("visibility","hidden");
		}

		if ($("[name=room]").val()==""){
			$("[name=room]").siblings("span").css("visibility","visible");
		}else{
			$("[name=room]").siblings("span").css("visibility","hidden");
		}

		if ($(".areaid").val()==""){
			$(".areaid").siblings("span").css("visibility","visible");
		}else{
			$(".areaid").siblings("span").css("visibility","hidden");
		}

		if ($(".villageid").val()==""){
			$(".villageid").siblings("span").css("visibility","visible");
		}else{
			$(".villageid").siblings("span").css("visibility","hidden");
		}

		if ($(".housetypeid").val()==""){
			$(".housetypeid").siblings("span").css("visibility","visible");
		}else{
			$(".housetypeid").siblings("span").css("visibility","hidden");
		}

		if($("[name=names]").val()!="" &&  $("[name=linkman]").val()!="" && $(".facilitieid").val()!=""
				&& $("[name=describe]").val()!="" && $("[name=title]").val()!="" && $("[name=storeyUser]").val()!=""
				&& $("[name=storeySum]").val()!="" && $(".renovation").siblings("span").val()!="" && $("[name=price]").val()!=""
				&& $("[name=houseSize]").val()!="" && $("[name=defend]").val()!="" && $("[name=hall]").val()!=""
				&& $("[name=room]").val()!="" && $(".areaid").val()!="" && $(".villageid").val()!="" && $(".housetypeid").val()!=""){
			$.ajax({
				url:"http://localhost:8080/house/save4",
				data:$("form").serialize(),
				type:"post",
				dataType:"json",
				success:function (data){
					if(data){
						alert("新增成功!");
						location.href="http://localhost:8080/backer/syshomepage";
					}else{
						alert("新增失败!");
					}
				}
			})
		}else{
			alert("文本框不能为空!");
		}



	});
	$(function () {
		$.ajax({
			url:"http://localhost:8080/house/listhousetype",
			type:"post",
			dataType:"json",
			success:function(data){
				$.each(data,function(i,d) {
					$(".housetype").after("<option value='"+d.id+"'>"+d.name+"</option>")
				});
			}
		});

		$.ajax({
			url:"http://localhost:8080/house/listvillage",
			type:"post",
			dataType:"json",
			success:function(data){
				$.each(data,function(i,d) {
					$(".village").after("<option value='"+d.id+"'>"+d.name+"</option>")
				});
			}
		});

		$.ajax({
			url:"http://localhost:8080/house/listarea",
			type:"post",
			dataType:"json",
			success:function(data){
				$.each(data,function(i,d) {
					$(".areas").after("<option value='"+d.id+"'>"+d.name+"</option>")
				});
			}
		});
		$.ajax({
			url:"http://localhost:8080/house/listrenovation",
			type:"post",
			dataType:"json",
			success:function(data){
				$.each(data,function(i,d) {
					$(".renovation").after("<option value='"+d.id+"'>"+d.name+"</option>")
				});
			}
		});
		$.ajax({
			url:"http://localhost:8080/house/listfacilities",
			type:"post",
			dataType:"json",
			success:function(data){
				$.each(data,function(i,d) {
					$(".facilities").after("<option value='"+d.id+"'>"+d.name+"</option>")
				});
			}
		});
		$.ajax({
			url:"http://localhost:8080/house/listlabel",
			type:"post",
			dataType:"json",
			success:function(data){
				$.each(data,function(i,d) {
					$(".houselable").append("<div onclick='houseclick(this)' names="+d.id+" class=bq"+i+" n=bq"+i+" a="+0+">"+d.name+"</div>");
				});
			}
		});
	})

	$(".choosedate-div").click(function(){
		$(this).children().checked=true;
		$(this).toggleClass("color","#409eff");
	});
	$(".houselable div").click(function(){
		if($(this).attr("a")=="0" && $(".houselable").attr("v")!="5"){
			$(".houselable").next("div").css("visibility","hidden");
			$(".houselable").attr("v",($(".houselable").attr("v")*1)+1);
			$(this).addClass("isselect");
			$(this).css("color","#fff");
			$(this).attr("a","1");
			$("[name=name]").append("<input style='display: none;' class='txt "+$(this).attr("n")+"'"+" value="+$(this).text()+">");
		}else if($(this).attr("a")=="1"){
			$(".houselable").next("div").css("visibility","hidden");
			$(".houselable").attr("v",($(".houselable").attr("v")*1)-1);
			$(this).removeClass("isselect");
			$(this).css("color","#999999");
			$(this).attr("a","0");
			$("[name=name] ."+$(this).attr("n")).remove();
		}else{
			$(".houselable").next("div").css("visibility","visible");
		}
	});

	$(".isblue").click(function(){
		$(".isblue").removeClass("blueline");
		$(this).addClass("blueline");
	});
	$(".isblue").blur(function(){
		$(".isblue").removeClass("blueline");
	});
	$(".rq").blur(function(){
		if ($(this).val()=="") {
			$(".rq").next("span").css("visibility","visible");
		} else{
			$(".rq").next("span").css("visibility","hidden");
		}
	});
	$(".area").blur(function(){
		if ($(this).val()=="") {
			$(".area").next("span").css("visibility","visible");
		} else{
			$(".area").next("span").css("visibility","hidden");
		}
	});
	$(".price").blur(function(){
		if ($(this).val()=="") {
			$(".price").next("span").css("visibility","visible");
		} else{
			$(".price").next("span").css("visibility","hidden");
		}
	});
	$(".zlc,.lc").blur(function(){
		if ($(".zlc").val()=="" || $(".lc").val()=="") {
			$(this).next("span").css("visibility","visible");
			$(this).next().next("span").css("visibility","visible");
		} else{
			$(this).next("span").css("visibility","hidden");
			$(this).next().next("span").css("visibility","hidden");
		}
	});

</script>
</html>
